﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <title>新闻显示</title>
    <link href="~/EasyUI/themes/icon.css" rel="stylesheet" />
    <link href="~/EasyUI/themes/default/easyui.css" rel="stylesheet" />
    <script type="text/javascript" src="~/Scripts/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="~/EasyUI/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="~/Scripts/jquery.validate.min.js"></script>

    <script src="~/Scripts/Showdatetime.js"></script>
    <script type="text/javascript" src="~/Scripts/jquery.msgProcess.js"></script>

    <script type="text/javascript">
        $(function () {

            $("#btnserch").click(function () {
                $('#tbList').datagrid('load', {
                    typeid: $('#newstype').val(),
                    keyword: $('#txtkey').val()
                });
            })

            $('#editWindow').window('close');

            $("#tbList").datagrid({
                width: 'auto',
                height: 'auto',
                fitColumns: true,
                striped: true,
                singleSelect: true,
                url: '/admin/news/NewList',
                //queryParams:{},
                loadMsg: '数据加载中请稍后……',
                pagination: true,//启用分页，默认每页10行
                rownumbers: false,//显示行号.
                pageSize: 10,//设置 页容量为 5
                pageList: [5, 10, 20],//设置 页容量下拉框
                columns: [[

                    { field: 'id', title: 'id', width: 30 },
                    { field: 'title', title: '新闻标题', width: 150 },
                    { field: 'newsImage', title: '图片', width: 100, formatter: function (value) {
                        if (value=="" || value==null) {
                            return "<img width='200' height='160' src='../../upImg/noimg2.jpg'>";
                        }
                        else {
                            return "<img width='200' height='160' src='../../upImg/" + value + "'>";
                        }

                    } },
                    { field: 'typeName', title: '新闻类型', width: 50 },
                    {
                    field: 'addtime', title: '添加时间', width: 120, formatter: function (value) {
                        var aa = eval('new ' + (value.replace(/\//g, '')));
                        return aa.format("yyyy-MM-dd hh:mm:ss");
                           }
                      }
                ]],
                toolbar: [{
                    iconCls: 'icon-add',
                    text: "新增",
                    handler: addRow
                }, '-', {
                    iconCls: 'icon-remove',
                    text: "删除",
                    handler: removeRow
                }, '-', {
                    iconCls: 'icon-edit',
                    text: "编辑",
                    handler: editRow
                }, '-', {
                    iconCls: 'icon-more',
                    text: "详情",
                    handler: detailRow
                }, '-', {
                    iconCls: 'icon-more',
                    text: "查看评论",
                    handler: commentRow
                }],
                onSelect: function (rowI, rowD) {
                    selectedRowIndex = rowI;//将选中行的下标 设置给全局变量
                },
                onDblClickRow: function () {
                    editRow();
                }
            });
        })

        //选中行的下标
        var selectedRowIndex = -1;


        //编辑按钮方法
        function detailRow() {
            //获取选中行里的数据！
            var rowData = $("#tbList").datagrid("getSelected");
            if (rowData) {
                window.location = "/admin/news/detailNews?id=" + rowData.id;

            }
        }

        //编辑按钮方法
        function editRow() {
            //获取选中行里的数据！
            var rowData = $("#tbList").datagrid("getSelected");
            if (rowData) {
                window.location = "/admin/news/EditNews?id=" + rowData.id;

            }
        }

        //新增按钮方法
        function addRow() {
           // $('#editWindow').window('open');

            window.location = "/admin/News/AddNews"

        }

        //删除方法
        function removeRow() {
            //获取选中行里的数据！
            var rowData = $("#tbList").datagrid("getSelected");
            if (rowData) {
                $.post("/admin/news/DleNews", "id=" + rowData.id, function (jsonObj) {
                    $.procAjaxData(jsonObj, function () {
                        $("#tbList").datagrid("reload");//删除成功后 刷新页面
                    });
                }, "JSON");
            }
        }


        //查看评论
        function commentRow() {
            var rowData = $("#tbList").datagrid("getSelected");
            if (rowData) {
                window.location = "/admin/Comment/sonindex?nid=" + rowData.id;

            }

        }



    </script>
</head>
<body>

    <div style=" margin:15px 0px 20px 50px">
        类型: @Html.DropDownList("newstype", @ViewBag.newstype as IEnumerable<SelectListItem>)  &nbsp; &nbsp; &nbsp;
        标题：<input id="txtkey" type="text" /> &nbsp; &nbsp;
        <input id="btnserch" type="button" value="搜索" />

    </div>
    <table id="tbList" style="width:auto;height:auto"></table>

    <div id="editWindow" class="easyui-window" title="My Window" style="width:900px;height:400px;"
         data-options="iconCls:'icon-save',modal:true">

    </div>
</body>
</html>